package com.hyt.it.ogt.pj.asynchronous;

import java.util.HashSet;
import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.hyt.it.ogt.pj.model.vo.SynDataVo;
import com.hyt.it.ogt.pj.service.ISynDataService;
import com.hyt.it.ogt.ykcj.domain.exchange.MessageInfo;
import com.hyt.it.ogt.ykcj.service.exchange.IApiLogService;

import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
/****
 * 现考现评同步成绩线程
 * @author huangwu
 */
@Slf4j
public class Ayns2Cj implements Runnable {

    private Set<String> taskIds = new HashSet<>();
    private ISynDataService synDataService;
    private IApiLogService iApiLogService;
    private String source;

    @Override
    public void run() {
        try {
            log.info("## ayns2cj start taskIds:{}", JSON.toJSON(taskIds));
            if (CollUtil.isNotEmpty(taskIds)) {
                for (String taskId : taskIds) {
                    SynDataVo synDataVo = synDataService.synDataToCJ(taskId);
                    // 同步成绩系统
                    String syncJson = JSON.toJSONString(synDataVo);
                    MessageInfo messageInfo = new MessageInfo();
                    messageInfo.setMsg(syncJson);
                    log.info("## saveCandidateInfo params:[{}]", JSON.toJSON(messageInfo));
                    iApiLogService.saveCandidateInfo(messageInfo);
                    log.info("## saveCandidateInfo result finish");
                }
            }
            log.info("## ayns2cj end");
        } catch (Exception e) {
            log.error("## ayns2cj error", e);
        }
    }

    public Set<String> getTaskIds() {
        return taskIds;
    }

    public void setTaskIds(Set<String> taskIds) {
        this.taskIds = taskIds;
    }

    public ISynDataService getSynDataService() {
        return synDataService;
    }

    public void setSynDataService(ISynDataService synDataService) {
        this.synDataService = synDataService;
    }

    public IApiLogService getIApiLogService() {
        return iApiLogService;
    }

    public void setIApiLogService(IApiLogService iApiLogService) {
        this.iApiLogService = iApiLogService;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }
    
}
